/**
 * @author takaratsunehito
 */

/**
 * アラーム型のタイマー
 * 
 * @param {Integer} target_time カウントダウン対象の時間
 */
function AlarmTimer(target_time) {
	this.is_stoped = true;
	this.target_time = target_time;
};

AlarmTimer.parse = function(input){
	var inputArray = input.split(" ");
	var dateArray = inputArray[0].split("/");
	var timeArray = inputArray[1].split(":");
	var year = dateArray[0];
	var month = dateArray[1];
	var day = dateArray[2];
	var hour = timeArray[0];
	var minute = timeArray[1];
	
	return new Date(year, month - 1, day, hour, minute).getTime();
};

AlarmTimer.prototype = {
    getString: function(){
        var now = new Date().getTime();
        var count = Math.ceil(Math.max((this.target_time - now) / 1000, 0));
		if(count == 0){
			this.stop();
		}
		
        var hour = Math.floor(count / (60 * 60));
        var minute = Math.floor(count / 60 % 60);
        var second = count % 60;
        
        var timeString = "%02.0d:%02.0d:%02.0d".sprintf(hour, minute, second);;
		return timeString;
    },
    
    start: function(){
		this.is_stoped = false;
    },
    
    stop: function(){
    	this.is_stoped = true;
    },
    
    isStoped: function(){
    	return this.is_stoped;
    }
};
